﻿using MyMES.Domain.yjb;
using MyMES.Writer.API.Workflow;
using WorkflowCore.Interface;
using IApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime;

namespace MyMES.Writer.API.Extensions
{
    public static class ConfigureExtensio
    {
        public static IApplicationBuilder UserWorkflow(this IApplicationBuilder app)
        {
            var host = app.ApplicationServices.GetService<IWorkflowHost>();
            host.RegisterWorkflow<CompletionApprovalWorkflowd, Approval>();
            host.Start();
            
            var appLifetime=app.ApplicationServices.GetService<IApplicationLifetime>();
            appLifetime.ApplicationStopping.Register(() =>
            {
                host.Start();
            });

            return app;
        }
    }
}
